<?php // no direct access
defined('_JEXEC') or die('Restricted access');
$Itemid = JRequest::getVar( 'Itemid', 0, 'get', 'int' );
jimport('joomla.filesystem.folder');
jimport('joomla.filesystem.file');
jimport('joomla.filesystem.path');
jimport('joomla.client.helper');
JHTML::stylesheet('base.css', JURI::root().'components/com_simplelisting/css/');
JHTML::stylesheet('listing.css', JURI::root().'/components/com_simplelisting/css/themes/'.$this->select_theme.'/');
?>
<script language="javascript" type="text/javascript">
</script>

<div id="listing_details"><!-- Start main container div-->
    <div id="listing_details_inner"><!-- Start inner div -->

        <form method="post" name="adminForm" id="adminForm" class="form-validate">
        <div class="header"><!-- Start header container -->
           <table class="general_details">
                <tbody>
                   <tr>
                      <?php if ($this->simplelisting->name == '') { ?>
                           <td class="cw_title_main">
                                <?php echo JText::_('LABEL_NEW');?>
                           </td>
                        <?php } else { ?>
                           <td class="cw_title_main">
                                <?php echo $this->simplelisting->name;?>
                           </td>
                           <?php } ?>
                   </tr>
                </tbody>
           </table>
        </div><!-- End header container -->
        <span id="cw_back_button_top">
            <button  type="button"  onClick="javascript:window.location='<?php echo JRoute::_('index.php?option=com_simplelisting&view=manage&layout=manage' ); ?>'"><?php echo JText::_('BT_CANCEL'); ?></button>
        </span>
    <?php
    $user =& JFactory::getUser();
    if ($user->guest) { ?>
         <div style="width:100%; height:10px;"></div>
            <input type="button" onClick="javascript:window.location='<?php echo JRoute::_( 'index.php?option=com_user&view=login'); ?>'" value="<?php echo JText::_('BT_LOGIN'); ?>" class="button" >
         <div style="width:100%; height:10px;"></div>
    <?php
    } elseif ($user->usertype == "Super Administrator" || $user->usertype == "Administrator" || $user->usertype == "Manager" || $user->usertype == "Registered" ){
    ?>
        <div style="width:100%; height:10px;"></div> 
        <table class="general_fields">
        <tr>
           <?php if ( $this->params->get( 'name_label' ) ) : ?>
           <td class="label">
                <?php echo $this->name_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_NAME').': '?>
           </td>
           <?php endif ?>
            <td class="content">
                <input type="text" name="name" id="name" size="20" maxlength="250" value="<?php echo $this->simplelisting->name; ?>" class="required" />
            </td>
        </tr>
        <tr>
           <?php if ( $this->params->get( 'description_label' ) ) : ?>
           <td class="label">
                <?php echo $this->description_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_DESCRIPTION').': '?>
           </td>
           <?php endif ?>
            <td class="content">
                <?php
                    $editor =& JFactory::getEditor();
                    echo $editor->display('description', $this->simplelisting->description, '100%', '100%', '70', '40', array('pagebreak', 'readmore', 'image') );
                    ?>
            </td>
        </tr>
        <?php if ( $this->params->get( 'show_address_admin' ) ) : ?>
        <tr>
           <?php if ( $this->params->get( 'address_label' ) ) : ?>
           <td class="label">
                <?php echo $this->address_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_ADDRESS').': '?>
           </td>
           <?php endif ?>
            <td class="content">
                <textarea name="address" id="address"  class="inputbox" cols="30"><?php echo $this->simplelisting->address; ?></textarea>
            </td>
        </tr>
        <?php endif ?>
        <?php if ( $this->params->get( 'show_country_admin' ) ) : ?>
        <tr>
           <?php if ( $this->params->get( 'country_label' ) ) : ?>
           <td class="label">
                <?php echo $this->country_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_COUNTRY').': '?>
           </td>
           <?php endif ?>
            <td class="content">
                <?php
                    $db =& JFactory::getDBO();
                    $query = 'SELECT a.* FROM #__simplelisting_countries as a ORDER BY a.ordering ASC';
                    $db->setQuery( $query );
                    $countrylist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_COUNTRY' ), 'id', 'name' );
                    $countrylist = array_merge( $countrylist, $db->loadObjectList() );
                    $lists['id']   = JHTML::_('select.genericlist', $countrylist, 'countries_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->countries_id );
                    echo $lists['id'];

                ?>
           </td>
        </tr>
        <?php endif ?>
        <tr>
           <?php if ( $this->params->get( 'category_label' ) ) : ?>
           <td class="label">
                <?php echo $this->category_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_CATEGORY').': '?>
           </td>
           <?php endif ?>
            <td class="content">
               <?php
                    $db =& JFactory::getDBO();
                    $query = 'SELECT a.* FROM #__simplelisting_categories as a WHERE a.published=1 ORDER BY a.ordering ASC';
                    $db->setQuery( $query );
                    $categorylist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_CATEGORY' ), 'id', 'name' );
                    $categorylist = array_merge( $categorylist, $db->loadObjectList() );
                    $lists['id']   = JHTML::_('select.genericlist', $categorylist, 'category_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->category_id );
                    echo $lists['id'];
                ?>
            </td>
         </tr>
        <tr>
           <?php if ( $this->params->get( 'type_label' ) ) : ?>
           <td class="label">
                <?php echo $this->type_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_TYPE').': '?>
           </td>
           <?php endif ?>
            <td class="content">
               <?php
                    $db =& JFactory::getDBO();
                    $query = 'SELECT a.* FROM #__simplelisting_types as a WHERE a.published=1 ORDER BY a.ordering ASC';
                    $db->setQuery( $query );
                    $type[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_TYPE' ), 'id', 'name' );
                    $type = array_merge( $type, $db->loadObjectList() );
                    $lists['id']   = JHTML::_('select.genericlist', $type, 'type_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->type_id );
                    echo $lists['id'];
                ?>
           </td>
        </tr>
         <?php if ( $this->params->get( 'show_extras_admin' ) ) : ?>
        <tr>
           <?php if ( $this->params->get( 'extras_label' ) ) : ?>
           <td class="label">
                <?php echo $this->extras_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_EXTRAS').': '?>
           </td>
           <?php endif ?>
             <td class="content">
                <?php
                    $db =& JFactory::getDBO();
                    $query = 'SELECT a.* FROM #__simplelisting_extras as a ORDER BY a.ordering ASC';
                    $db->setQuery( $query );
                    $extralist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_EXTRAS' ), 'id', 'name' );
                    $extralist = array_merge( $extralist, $db->loadObjectList() );
                    $lists['id']   = JHTML::_('select.genericlist', $extralist, 'extra_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->extra_id );
                    echo $lists['id'];
                ?>
            </td>
         </tr>
         <?php endif ?>
         <?php if ( $this->params->get( 'show_layout_admin' ) ) : ?>
        <tr>
           <?php if ( $this->params->get( 'layout_label' ) ) : ?>
           <td class="label">
                <?php echo $this->layout_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_LAYOUT').': '?>
           </td>
           <?php endif ?>
            <td class="content">
            <?php
                $db =& JFactory::getDBO();
                $query = 'SELECT a.* FROM #__simplelisting_layouts as a ORDER BY a.ordering ASC';
                $db->setQuery( $query );
                $layoutlist[]   = JHTML::_('select.option', '0', JText::_( 'SELECT_LAYOUT' ), 'id', 'name' );
                $layoutlist = array_merge( $layoutlist, $db->loadObjectList() );
                $lists['id']   = JHTML::_('select.genericlist', $layoutlist, 'layout_id', 'class="inputbox" size="1"','id', 'name', $this->simplelisting->layout_id );
                echo $lists['id'];
            ?>
            </td>
        </tr>
        <?php endif ?>
        <?php if ( $this->params->get( 'show_price_admin' ) ) : ?>
        <tr>
           <?php if ( $this->params->get( 'price_label' ) ) : ?>
           <td class="label">
                <?php echo $this->price_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_PRICE').': '?>
           </td>
           <?php endif ?>
            <td class="content">
                <input type="text" name="price" id="price" size="20" maxlength="50" value="<?php echo $this->simplelisting->price; ?>" class="inputbox" />
            </td>
        </tr>
        <?php endif ?>
        <?php if ( $this->params->get( 'show_facilities_admin' ) ) : ?>
        <tr>
           <?php if ( $this->params->get( 'facilities_label' ) ) : ?>
           <td class="label">
                <?php echo $this->facilities_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_FACILITIES').': '?>
           </td>
           <?php endif ?>
            <td class="content">
               <table>
                <?php
                    $db =& JFactory::getDBO();
                    $query = 'SELECT a.* FROM #__simplelisting_facilities as a ORDER BY a.ordering ASC';
                    $db->setQuery( $query );
                    $r = $db->loadObjectList();

                    $facilities = array();
                    if ( !empty($this->simplelisting->facilities) ) {
                        $facilities = explode( ',' ,  $this->simplelisting->facilities );
                    }
                    $count = 1;
                    $column = 1;
                    foreach($r as $k=> $row)
                    {
                        $checked = '';
                        if ( in_array($row->id, $facilities) ) {
                            $checked = 'checked="checked"' ;
                        }
                        $id    = $row->id;
                        $value = $row->name;
                        $html = '<input type="checkbox" name="facilities['.$k.']" value="'.$id.'"' .$checked .' />'.$value;
                        if ($column == 1)
                        {
                            printf("<tr><td id='items'>%s</td>",$html);
                        }else{
                        printf("<td id='items'>%s</td></tr>",$html);
                        }

                        $count += 1;

                        $column = $count %2;
                    }
                ?>
                </table>
            </td>
        </tr>
        <?php endif ?>
        <tr>
           <?php if ( $this->params->get( 'published_label' ) ) : ?>
           <td class="label">
                <?php echo $this->published_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_PUBLISHED').': '?>
           </td>
           <?php endif ?>
           <td class="content"><?php echo JHTML::_('select.booleanlist',  'published', '', $this->simplelisting->published ); ?></td>
       </tr>
        <tr>
           <?php if ( $this->params->get( 'posted_label' ) ) : ?>
           <td class="label">
                <?php echo $this->posted_label; ?>
           </td>
           <?php else :?>
           <td class="label">
            <?php echo JText::_('LABEL_POSTED_DATE').': '?>
           </td>
           <?php endif ?>
           <td class="content"><?php echo JHTML::_('date',  $this->simplelisting->date_created,  JText::_('DATE_FORMAT_LC2') ) ?></td>
       </tr>
       <tr>
           <td id="items" colspan=3>
           <?php
                if(empty($this->simplelisting->id)):
                $user =& JFactory::getUser();
                ?>
                <input type="hidden" name="create_by" value="<?php echo $user->id; ?>"/>
                <input type="hidden" name="date_created" value="<?php echo date('Y-m-d H:i:s') ?>"/>
                <?php else:
                $user =& JFactory::getUser();
                ?>
                <input type="hidden" name="modify_by" value="<?php echo $user->id; ?>"/>
                <input type="hidden" name="date_modified" value="<?php echo date('Y-m-d H:i:s') ?>"/>
                <?php endif; ?>
                <br />
                <button type="button"  onClick="javascript:window.location='<?php echo JRoute::_('index.php?option=com_simplelisting&view=manage&layout=manage' ); ?>'"><?php echo JText::_('BT_CANCEL'); ?></button>
                <button class="form-validate" type="submit"><?php echo JText::_('BT_SAVE'); ?></button>
                <input type="hidden" name="option" value="com_simplelisting"/>
                <input type="hidden" name="view" value="manage" />
                <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>
                <input type="hidden" name="task" value="save" />
                <?php echo JHTML::_('form.token'); ?>
            </td>
       </tr>
    </table>
 </form>
<?php if(!empty($this->simplelisting->id)):?>

    <div style="width:100%; height:10px;"></div>
    <table class="general_fields" width="100%" border="0">
       <tbody>
       <tr>
          <td colspan="6" class="cw_title_extras">
              <?php echo JText::_('FT_AUTHOR_DETAILS').': '?>
          </td>
       </tr>
      <tr>
           <td colspan="6" class="cw_title_separator"></td>
       </tr>
       <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_NAME').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->username); ?></td>
       </tr>
       <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_TELEPHONE').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->tel); ?></td>
       </tr>
       <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_MOBILE').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->mobile); ?></td>
       </tr>
       <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_FAX').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->fax); ?></td>
       </tr>
       <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_EMAIL').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->email); ?></td>
       </tr>
      <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_COUNTRY').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->usercountry); ?></td>
       </tr>
      <tr>
           <td class="label"><?php echo JText::_('LABEL_CONTACT_MISC').': '?></td>
           <td class="content"><?php echo $this->escape( $this->simplelisting->misc); ?></td>
       </tr>
   </table>

   <div style="width:100%; height:10px;"></div>

    <form action="" method="post" enctype="multipart/form-data">
        <table class="general_fields" width="100%" border="0">
           <tbody>
               <tr>
                  <td colspan="6" class="cw_title_extras"><?php echo JText::_('FT_MAIN_IMAGE')?></td>
               </tr>
               <tr>
                   <td colspan="6" class="cw_title_separator"></td>
               </tr>
                <tr>
                    <td height="120px"  valign="top">
                        <input type="file" name="upload_file"  class="button" />
                        <input type="submit" name="submit" value="<?php echo JText::_('BT_UPLOAD') ?>" class="button" /><br /><br />
                    <?php
                    $main = JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id;
                    if ( !JFolder::exists($main) ) { JFolder::create($main); }
                    if ( is_file( $main.'/main.jpg') ) : ?>
                        <span class="cw_image_teaser">
                            <a href="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ?>">
                            <img src="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/main.jpg' ?>" border="5" vspace="5"  alt="No Image" width="100" />
                            </a>
                            <a href="<?php echo JRoute::_('index.php?option=com_simplelisting&task=delete_main&id='.$this->simplelisting->id) ; ?>">
                            <?php echo JHTML::_('image.site', 'delete.png', '/components/com_simplelisting/images/') ?>
                            </a>
                        </span>
                    <?php endif ?>
                    </td>
                </tr>
            </tbody>
        </table>
        <input type="hidden" name="option" value="com_simplelisting"/>
        <input type="hidden" name="view" value="manage" />
        <input type="hidden" name="task" value="upload_main" />
        <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>
        <?php echo JHTML::_('form.token'); ?>
    </form>

    
    <form action="" method="post" enctype="multipart/form-data">
    <div style="width:100%; height:10px;"></div>
        <table class="general_fields" width="100%" border="0">
           <tbody>
                <tr>
                  <td colspan="6" class="cw_title_extras"><?php echo JText::_('FT_GALLERY')?></td>
                </tr>
                <tr>
                   <td colspan="6" class="cw_title_separator"></td>
                </tr>
                <tr>
                    <td height="120px"  valign="top">
                        <input type="file" id="upload_file" name="upload_file[]" class="button">
                        <input type="submit" name="submit" value="<?php echo JText::_('BT_UPLOAD') ?>" class="button" /><br /><br />
                        <?php
                        $TrackDirPath = JPATH_ROOT.'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/second/';
                        if ( !JFolder::exists($TrackDirPath) ) { JFolder::create($TrackDirPath); }
                        $TrackDir = opendir($TrackDirPath);
                        $count = 0;
                        while (($file = readdir($TrackDir)) !== false) {
                        if ($file == "." || $file == "..") { }
                        else {
                        ?>
                        <span class="cw_image_teaser">
                        <a href="<?php echo JURI::root().'/components/com_simplelisting/images/gallery/'.$this->simplelisting->id.'/second/'.$file; ?>">
                        <img src="<?php echo JURI::root() ?>/components/com_simplelisting/images/gallery/<?php echo $this->simplelisting->id.'/second/'.$file; ?>" border="5" vspace="5" alt="No Image" width="100"/>
                        </a>
                        <a href="<?php echo JRoute::_('index.php?option=com_simplelisting&task=delete_sec&id='.$this->simplelisting->id.'&image='.$file) ; ?>">
                        <?php echo JHTML::_('image.site', 'delete.png', '/components/com_simplelisting/images/') ?><br />
                        </a>
                        </span>
                        <?php
                                }
                             }
                             @ closedir($TrackDir);
                        ?>
                    </td>
                </tr>
        </table>
        <input type="hidden" name="option" value="com_simplelisting"/>
        <input type="hidden" name="view" value="manage" />
        <input type="hidden" name="task" value="upload_second" />
        <input type="hidden" name="id" value="<?php echo $this->simplelisting->id; ?>"/>
        <?php echo JHTML::_('form.token'); ?>
    </form>
<?php endif ?>
<?php } ?>
            <?php if ( $this->params->get( 'show_poweredby' ) ) : ?>
                <div class="cw_powerbyfront">
                    <span class="cw_powerbyfront"><?php echo JTEXT::_('POWEREDBY_MSG'); ?> <a href="http://www.celtaweb.com" target="_blank" title="CeltaWeb">CeltaWeb</a> </span>
                </div>
            <?php endif ?>
    </div><!-- listing_details_inner-->
</div><!-- listing_details-->


